<?php
// +----------------------------------------------------------------------
// | Copyright (c) 2018-2018 http://www.donglixia.net All rights reserved.
// +----------------------------------------------------------------------
// | Author: 十万马 <962863675@qq.com>
// +----------------------------------------------------------------------
// | DateTime: 2018-02-09 16:17
// +----------------------------------------------------------------------
// | 父类控制器
// +----------------------------------------------------------------------
namespace app\english\controller;

use app\common\controller\Base as CoreBase;
use think\Db;

class Base extends CoreBase
{
    protected $currentModel;//声明当前模型
    
    protected function _initialize()
    {
        parent::_initialize();
        \think\Hook::listen('view_init');//添加行为标签位，触发自动执行
        define('VIEW_PATH', APP_PATH . $this->request->module() . '/view' . DS);

        $data = Db::name('system_config')->where('pid', '<>', 0)->field('id,view_name,sys_code,sys_value')->select();
        $config = [];
        foreach ($data as $k=>$v) {
            $config[$v['sys_code']] = $v['sys_value'];
        }
        $this->assign('config', $config);//系统设置信息
    }

    public function index()
    {
        return $this->fetch();
    }

    /**
     * 空方法，不存在方法名时，自动渲染
     * @param $name
     * @return mixed
     */
    public function _empty($name)
    {
        //初始化模版路径，指向404页面
        $template = STATIC_PATH.'/404.html';
        //根据请求链接判断模版是否存在
        if (file_exists(VIEW_PATH . strtolower($this->request->controller()) . DS . $name . '.html')) {
            $template = VIEW_PATH . strtolower($this->request->controller()) . DS . $name . '.html';
        } elseif (file_exists(VIEW_PATH . $name . '.html')) {
            $template = VIEW_PATH . $name . '.html';
        }
        return $this->fetch($template);
    }


}
